<template>
  <div class="container">
    <el-form ref="form" :model="form" label-width="80px">

      <el-row type="flex">
        <el-col :span="12">
          <el-form-item label="成本价格">
            <el-row type="flex">
              <el-col :span="12">
                <div class="input-right">
                  <el-input v-model="form.costBegin" oninput="value=value.replace(/[^0-9.]/g,'')"></el-input>
                </div>
              </el-col>
              <el-col :span="12">
                <div class="input-left">
                  <el-input placeholder="至" v-model="form.costEnd" oninput="value=value.replace(/[^0-9.]/g,'')"></el-input>
                </div>
              </el-col>
            </el-row>
          </el-form-item>
        </el-col>

        <el-col :span="12">
          <el-form-item label="售卖价">
            <el-row type="flex">
              <el-col :span="12">
                <div class="input-right">
                  <el-input v-model="form.salesBegin" oninput="value=value.replace(/[^0-9.]/g,'')"></el-input>
                </div>
              </el-col>
              <el-col :span="12">
                <div class="input-left">
                  <el-input placeholder="至" v-model="form.salesEnd" oninput="value=value.replace(/[^0-9.]/g,'')"></el-input>
                </div>
              </el-col>
            </el-row>
          </el-form-item>
        </el-col>

      </el-row>



      <el-row type="flex">
        <el-col :span="12">
          <el-form-item label="是否启用" >
            <el-switch v-model="form.status"></el-switch>
          </el-form-item>
        </el-col>
        <!--       状态-->
        <el-col :span="12">
          <el-form-item label="销售方式" >
            <el-radio  label="0" v-model="form.salesType">按件</el-radio>
            <el-radio label="1" v-model="form.salesType">按重量</el-radio>
          </el-form-item>
        </el-col>
        <!--       单位-->

      </el-row>

      <el-form-item>
        <el-button type="primary" @click="addCondition">添加</el-button>
        <el-button >取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  name: "goodsSearch",
  data(){
    return{
      form:{
        costBegin:0,
        costEnd:0,
        salesBegin:0,
        salesEnd:0,
        status:true,
        isPiece:0,
        isWeight:1,
        salesType:'0',
      }
    }
  },
  methods:{
    isNumber(value){
      return (typeof value === 'number' && !isNaN(value));
    },
    addCondition(){
      //校验数据
      if (this.form.salesBegin>this.form.salesEnd){
        this.$message({
          message:'销售价格的起始价格不应该大于结束价格',
          type:"warning"
        })
        return false;
      }
      if (this.form.costBegin>this.form.costEnd){
        this.$message({
          message:'成本价格的起始价格不应该大于结束价格',
          type:"warning"
        })
        return false;
      }
      //处理数据
      if (this.form.status) this.form.status=0;
      else this.form.status=1;
      if (this.form.salesType=='0') {
        this.form.isPiece=0
        this.form.isWeight=1;
      }
      else {
        this.form.isPiece=1
        this.form.isWeight=0;
      }
      console.info('查看组装好了的数据',this.form)
      this.$bus.$emit('getSearchCondition',this.form)
    }
  }
}
</script>

<style scoped lang="scss">
.input-left{
::v-deep.el-input__inner{
  border-left: none;
  border-top-left-radius: 0px;
  border-bottom-left-radius: 0px;
}
}

input-right{
::v-deep.el-input__inner{
  border-right: none;
  border-top-right-radius: 0px;
  border-bottom-right-radius: 0px;
}}
</style>